package com.admin.interfaces.task;

import com.admin.application.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;

/**
 * description 订单超过15分钟后自动取消.
 * Created with IntelliJ IDEA.
 * User: WeiDa
 * Date: 2017-5-1
 * Time: 14:31
 */
@Component
public class ScheduledTask {

    @Autowired
    private TaskService taskService;

    /**
     * description 每五分钟执行一次
     * User: WeiDa
     * Date: 2017-5-1
     * Time: 18:21
     */
    @Scheduled(cron = "* 0/5 * * * ? ")
    public void cancelInitOrder() throws InterruptedException {

        try {
            taskService.cancelInitOrder();
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

    @Scheduled(cron = "* 0/5 * * * ? ")
    public void cancelPreOrder() throws InterruptedException {
        try {
            taskService.cancelPreOrder();
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

    @Scheduled(cron = "* 0/10 * * * ? ")
    public void verifyOrder() throws InterruptedException {
        taskService.verifyOrder();
    }

    /**
     * description 维护预售时间
     * User: WeiDa0 0 1 1/1 * ?
     * Date: 2017-6-7
     * Time: 14:09
     */
    @Scheduled(cron = "0 45 0 * * ? ")
    public void editSaleDate() throws InterruptedException {
        taskService.editSaleDate();
    }
}
